//
//  QSProblemReprotInterface.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/4/3.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSProblemReprotInterface.h"
#import "QSRequestManager.h"
@implementation QSProblemReprotInterface
/**
* @brief 获取问题上报主列表
*/
+ (void)getApiProblemReportListWithPageIndex:(NSInteger)pageIndex
                                   WithMonth:(NSString *)month
                                andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSQSProblemReportListModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kProblemList];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    [bodyDic setValue:month forKey:@"month"];
    
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            QSQSProblemReportListModel *model = [QSQSProblemReportListModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 问题详情
*/
+ (void)getApiProblemDetailWithID:(NSInteger)id
andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSProblemDetailModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kProblemDetail];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(id) forKey:@"id"];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if(rspStatusAndMessage.code == kResponseSuccessCode){
            QSProblemDetailModel *model = [QSProblemDetailModel mj_objectWithKeyValues:responseDataDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 获取问题类型下拉列表
*/
+ (void)getApiProblemTypeListWithBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSArray *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kGetProblemType];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenReturnArrayGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSArray *responseArr) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseArr);
        }
    }];
}

/**
* @brief 获取街道列表
*/
+ (void)getApiTownListListWithBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kTownList];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
}

/**
 * @brief 获取公司列表 （模糊搜索）
 *TownShipId 街道ID
 *CompanyName 公司名称
*/
+ (void)getApiCompanyListWithPageIndex:(NSInteger )pageIndex
                            TownShipId:(NSString *)townShipId
                            CompanyName:(NSString *)companyName
                               andBlock:(void (^)(ResponseMessage *rspStatusAndMessage, QSProblemCompanyListModel *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kProblemCompanyList];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [bodyDic setObject:@(pageIndex) forKey:@"pageIndex"];
    [bodyDic setObject:@(10) forKey:@"pageSize"];
    if (townShipId) {
        [bodyDic setObject:townShipId forKey:@"townShipId"];
    }
    if (companyName) {
        [bodyDic setObject:companyName forKey:@"name"];
    }
    [QSRequestManager executeTokenGET:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            QSProblemCompanyListModel *model = [QSProblemCompanyListModel mj_objectWithKeyValues:responseDic];
            block(rspStatusAndMessage, model);
        }
    }];
}

/**
* @brief 提交问题
 *typeId 问题类型id
 *title 问题标题
 *info 描述信息
 *pic 描述图片
 *companyKey 企业
*/
+ (void)postNewProblemWithTypeId:(NSString *)typeId
                              Title:(NSString *)title
                            Info:(NSString *)info
                            Pic:(NSString *)pic
                      CompanyKey:(NSString *)companyKey
                        AndBlock:(void (^)(ResponseMessage *rspStatusAndMessage, NSDictionary *result))block{
    NSString *requestURL = [[kBaseUrlPrefix stringByAppendingString:kSanFangBack] stringByAppendingString:kProblemAdd];
    NSMutableDictionary *bodyDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    if (typeId) {
        [bodyDic setObject:typeId forKey:@"typeId"];
    }
    [bodyDic setObject:title forKey:@"title"];
    [bodyDic setObject:info forKey:@"info"];
    if (pic) {
        [bodyDic setObject:pic forKey:@"pic"];
    }
    [bodyDic setObject:companyKey forKey:@"companyKey"];
    
    [QSRequestManager executeJSONTokenPOST:requestURL requestBody:bodyDic andBlock:^(ResponseMessage *rspStatusAndMessage, NSDictionary *responseDataDic) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            block(rspStatusAndMessage, responseDataDic);
        }
    }];
    
}

@end
